/**
 * Validiert das Event-Datum.
 * 
 * @author Michael Serajnik
 */

package at.fhj.itm10.ticketmaster.validators;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

@FacesValidator(value = "EventDateValidator")
public class EventDateValidator implements Validator {

	public void validate(FacesContext context, UIComponent component, Object value)
			throws ValidatorException {
		
		String eventDate = (String) value;
		String regEx = "(0[1-9]|[12][0-9]|3[01])\\.(0[1-9]|1[012])\\.(19|20)\\d\\d";
		
		if(eventDate.length() == 0 || eventDate.matches(regEx) == false) {
			throw new ValidatorException(new FacesMessage("Bitte gib ein g\u00FCltiges Datum im Format \"dd.MM.yyyy\" an."));
		}
		
	}

}